# Maintainer: Hristiyan Ivanov <hristiyan.d.ivanov@gmail.com>
pkgname=spacectl
pkgver=1.0.0
pkgrel=1
pkgdesc="A Utility wrapping Spacelift's GraphQL API for easy programmatic access in command-line contexts."
url="https://github.com/spacelift-io/spacectl"
arch="all"
license="MIT"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/spacelift-io/spacectl/archive/refs/tags/v$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare
	go mod download
}

build() {
	go build .

	for shell in bash fish zsh; do
		./spacectl completion $shell > spacectl.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm0755 spacectl -t "$pkgdir"/usr/bin/

	install -Dm0644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/

	install -Dm0644 spacectl.bash \
		"$pkgdir"/usr/share/bash-completion/completions/spacectl
	install -Dm0644 spacectl.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/spacectl.fish
	install -Dm0644 spacectl.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_spacectl
}

sha512sums="
9398b158cb1ed0b6fb40fdee3f7549ce7267a72c83855c128fb1a2154193c0e166aeef6bce0f6971dbd03263cb02795d5ee477a93179557b502a46d1299d81a1  spacectl-1.0.0.tar.gz
"
